<?php
/**
 * Nadëb (Makú-Nadëb)
 * 
 * @author     Mateus Martins <mateusweb@gmail.com>
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    http://www.gnu.org/licenses/gpl.html | GPL
 * @package    Nadeb
 * @version    1.0.0
 */


/**
 * Class Nadeb_MenuAdmin
 * Monta o XHTML do menu da area de administração
 * 
 * @category   Nadeb
 * @package    Nadeb_MenuAdmin
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    http://www.gnu.org/licenses/gpl.html | GPL
 */
class Nadeb_MenuAdmin
{
	/**
	 * @var object $configsIni
	 */
	private $configsIni;
	
	/**
	 * Metodo construtor armazena em configsIni as infos para montar o menu
	 * 
	 * @param string $_levelAccess define qual menu carrega dependendo do nivel do usuário
	 * @return void
	 */
	public function __construct($_levelAccess)
	{
		$levelAccess = $_levelAccess == 'master' || $_levelAccess == 'admin' ? "menu" : $_levelAccess;
		$this->configsIni = new Zend_Config_Ini("./application/ini/admin/menu/{$levelAccess}.ini", "menu");
	}
	
	/**
	 * Varre o config ini para montar um array com as info para montar o menu
	 */
	private function get_config()
	{
		foreach($this->configsIni as $key => $value)
			$values[] = $key;
		
		foreach($values as $obj => $name)
			foreach($this->configsIni->$values[$obj] as $key => $value)
				if(!is_object($value))
					$config[$name][$key] = $value;
				else
					foreach($value as $key1 => $value1)
						$config[$name][$key][$key1] = $value1;

		
		return $config;				
	}
	
	/**
	 * Retorna o XHTML do menu 
	 * 
	 * @return string
	 */
	public function get_xhtml()
	{
		$i      = 0;
		$links  = $this->get_config();
		$sample = '		<div id="box_menu" class="over_flow">' . "\n";
		foreach($links as $key => $array)
		{
			$sample .= '			<ul class="menu">' . "\n";
			$sample .= '				<li class="li_item" id="'.$key.'">' . "\n";
			$sample .= '					<a href="'.$array["link"].'" class="item"><b>'.$array["title"].'</b></a>' . "\n";
			if( isset( $array["subtitle"] ) )
			{
				$sample .= '					<div class="div_sub_menu" id="s'.$i++.'">' . "\n";
				$sample .= '						<ul class="sub_menu">' . "\n";
				foreach($array["subtitle"] as $subkey => $value)
					$sample .= '							<li class="sub_item"><a href="'.$array["sublink"][$subkey].'">'.$value.'</a></li>' . "\n";
				$sample .= '						</ul>' . "\n";
				$sample .= '					</div>' . "\n";
			}
			$sample .= '				</li>' . "\n";
			$sample .= '			</ul>' . "\n";
		}
		
		$sample .= '		</div>' . "\n";
		
		return $sample;
	}
}